<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script>
$(function(){
	getFloorNum();
});
//获取建筑数量列表（建筑名、楼号）
function getFloorNum() {
	var url = "bulidingNum/floorNum/getFloorNumByBId";
	//pid:建筑数量id 预留
	var bid = $("#buildingNumId").val();
	if(bid==null || bid==""){
		return false;
	}
	$.getJSON(url, {
		buildingNumId : bid
	}, function(data, status) {
		if (status == "success") {
			if(data.length>0){
				$.each(data, function(i, v) {
					if(v.site==0){//0 地上  1地下
						$("#number1").val(v.number);
						$("#height1").val(returnFloat(v.height));
						$("#entityId_id1").val(v.id);
					}else{
						$("#number2").val(v.number);
						$("#height2").val(returnFloat(v.height));
						$("#entityId_id2").val(v.id);
					}
				});
				$("#floorNum #btn_div2").show();
				$("#floorNum #btn_div1").hide();
				$("#floorNum #lcsl").find("input,textarea").attr("readonly",true);
			}
		}
	});
}

//重置表单
function resetFormFN(){
	$("#floorNum #lcsl").find("input").val("");
	$("#floorNum #number1").focus();
}
</script>
<!-- 楼层数量 -->
<form class="cmxform" id="floorNum" method="post" action="bulidingNum/floorNum/add">
		<div style="padding:0px">
		
		<div class="panel panel-default">
   			<div class="panel-body">
   				<!-- 楼层数量start-->
   				<table class="mytable" id="lcsl">
   					<tr class="style_border_bottom_red">
   						<td colspan="5"><span class="style_btn_red">地上</span>
   						</td>
   					</tr>
   					<tr>
   						<td  width="73" class="td-right"><span>楼层数量</span></td>
   						<td width="260"><input id="number1" name="number" /></td>
   						<td class="td-right"><span>建筑高度</span></td>
   						<td><input id="height1" name="height" /> m</td>
   						<td style="display:none;"><input id="site1" name="site" value="0"/></td>
   						<input type="hidden" id="entityId_id1" name="id" value=""/>
   					</tr>
   					<tr class="style_border_bottom_red">
   						<td colspan="4"><span class="style_btn_red">地下</span></td>
   					</tr>
   					<tr>
   						<td  width="73" class="td-right"><span>楼层数量</span></td>
   						<td width="260"><input id="number2" name="number" /></td>
   						<td  width="73" class="td-right"><span>建筑深度</span></td>
   						<td ><input id="height2" name="height" /> m</td>
   						<td style="display:none;"><input id="site2" name="site" value="1"/></td>
   						<input type="hidden" id="entityId_id2" name="id" value=""/>
   					</tr>
   				</table>
   				<!-- 楼层数量end-->
   				
			</div>
			</div>
			<div style="width:100%;text-align:center; padding-top:20px">
				<div id="btn_div1">
					<button class="btn btn-danger radius my-btn"
						onclick="saveFloorNum(0)" type="button">提交</button>
					<button class="btn btn-danger radius my-btn"
						onclick="saveFloorNum(1)" type="button">保 存</button>
					<a class="btn btn-default radius" onClick="resetForms('floorNum');">
						重置 </a>
					<br />
				</div>
				<div id="btn_div2" style="display:none;">
					<shiro:hasPermission name="permission:edit">
						<button id="modifyBtn" type="button" class="btn btn-danger radius my-btn"
							onclick="saveFloorNum(3)">启用编辑</button>
						<button class="btn btn-danger radius my-btn hidbtn"
							onclick="saveFloorNum(2)" type="button">保存修改</button>
						<button class="btn btn-default radius hidbtn" type="button" onClick="resetForms('floorNum');">
							重置 </button>
					</shiro:hasPermission>	
				</div>
	    	</div> 
	    	 
		</div>
</form>
<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script> 
<script src="js/form.js"></script>
<script type="text/javascript">
	
	$(function(){
		mySubmit("floorNum",initFloorNum,successFloorNum);
	})
	var optFloorNum;
	//optFloorNum操作字段，0：临时保存；1：新增；2：修改
	function saveFloorNum(val){
		optFloorNum=val;
		if(val==3){
			//解除锁定状态
			var index=layer.confirm('确定开启编辑状态？', {
			 	offset:'20%',
				shade:0
			}, function(){
			  //去除只读开启按钮编辑
			   $("#floorNum").find("input,textarea").attr("readonly",false);
			   $("#floorNum #modifyBtn").hide();
			  // $(".hidbtn").removeClass("hidbtn");
			  $("#floorNum .hidbtn").addClass("showbtn");
			   layer.close(index);
			});
		}else{
			
			$("#floorNum").submit();
		}
	}
	var fi;
	//封装表单数据为json
	function initFloorNum(){
		fi = layer.load(2);
		//封装地上数据
		var $t=$("#floorNum #lcsl tr:eq(1)");
		var ground=new Array();
		for(var i=0;i<$t.length;i++){
			var v=$t[i];
			var number=$(v).find("input[name='number']").val();
			var height=$(v).find("input[name='height']").val();
			var site='0';
			var id=$("#entityId_id1").val();
			if (!testNum(number)) {
				layer.msg("地上楼层数量请输入数值");
				$(v).find("input[name='number']")[0].focus();
				layer.close(fi);
				return null;
			}else if (!testNum(height)) {
				layer.msg("地上建筑高度请输入数值");
				$(v).find("input[name='height']")[0].focus();
				layer.close(fi);
				return null;
			}
			ground.push({id:id,number:number,height:height,site:site,fkFloorNum:'${requestScope.buildingNum.floorNum}',opt:optFloorNum});
		}
		
		//封装地下数据
		var $t=$("#floorNum #lcsl tr:eq(3)");
		for(var i=0;i<$t.length;i++){
			var v=$t[i];
			var number=$(v).find("input[name='number']").val();
			var height=$(v).find("input[name='height']").val();
			var site='1';
			var id=$("#entityId_id2").val();
			if (!testNum(number)) {
				layer.msg("地下楼层数量请输入数值");
				$(v).find("input[name='number']")[0].focus();
				layer.close(fi);
				return null;
			}else if (!testNum(height)) {
				layer.msg("地下建筑深度请输入数值");
				$(v).find("input[name='height']")[0].focus();
				layer.close(fi);
				return null;
			}
			ground.push({id:id,number:number,height:height,site:site,fkFloorNum:'${requestScope.buildingNum.floorNum}',opt:optFloorNum});
			
		}
		
		var formData={
			floorNum2:ground
		};
		return formData;		
	}
	
	//成功后调用方法
	function successFloorNum(responseText){
		layer.close(fi);
		if(responseText.success){
		layer.alert("保存成功！", {
					offset:'20%',
					shade:0.1
				}, function() {
        	parent.tabTypeShow=1;
        	location.reload();
        });
        	/* getFloorNum();
        	//$("#btn_div2 button:eq(1)").addClass();
        	$("#floorNum #modifyBtn").show();
        	$("#floorNum #btn_div2>button:gt(0)").removeClass("showbtn");
        	//显示当前tab
			$("#BN>li:eq(1) a").tab("show"); */
        	layer.close(fi);
		}else{
			alert('保存失败！');
			layer.closeAll();
		}
	}
</script>
  	
